package com.purengage.ipilih;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class Status extends TabActivity {
	private TabHost mTabHost;

	private void setupTabHost() {
		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if(Build.VERSION.SDK_INT >= 11)
			setTheme(android.R.style.Theme_Holo_Light_NoActionBar);
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_status);

		setupTabHost();
		//mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

		setupTab(new TextView(this), "Status", "Status2.class",
				R.drawable.survey_g);
		setupTab(new TextView(this), "Inbox", "Inbox.class",
				R.drawable.status_g);
		setupTab(new TextView(this), "Group", "Group.class",
				R.drawable.responden_g);
		
		final Intent intent = new Intent().setClass(this, AddStatus.class);
		
		
		getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener() {
		    @Override
		    public void onClick(View v) {		     
		    	startActivity(intent);
		    }
		});
		
		
		mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#dddddd"));
		mTabHost.setOnTabChangedListener(new OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {				
				
				if(tabId.equalsIgnoreCase("Status")){					
					startActivity(intent);
				}
			}			
		});
		
	}

	private void setupTab(final View view, final String tag,
			final String className, final int drawable) {
		View tabview = createTabView(mTabHost.getContext(), tag, drawable);

		Intent intent;
		intent = new Intent().setClass(this, Status2.class);
		if (className.equals("Status2.class")) {
			intent = new Intent().setClass(this, Status2.class);
		}
		if (className.equals("Inbox.class")) {
			intent = new Intent().setClass(this, Inbox.class);
		}
		if (className.equals("Group.class")) {
			intent = new Intent().setClass(this, Group.class);
		}
		TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
				.setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));			
		
		mTabHost.addTab(setContent);
		
	
	}
	


	private static View createTabView(final Context context, final String text,
			final int drawable) {
		View view = LayoutInflater.from(context).inflate(R.layout.tabs_status,
				null);
		TextView tv = (TextView) view.findViewById(R.id.tabsText);
		ImageView iv = (ImageView) view.findViewById(R.id.imgTab);
		tv.setText(text);
		iv.setImageResource(drawable);
		return view;
	}

}
